package week_9;

import java.util.Iterator;

public class CityNetwork<T>  extends IndirectedNetwork<T>{
    public CityNetwork()
    {
        super();
    }

    public void addCity(T city)
    {
        addVertex(city);
    }

    public void addEdge(T city1,T city2,double weight)
    {
        addEdge(getIndex(city1),getIndex(city2),weight);
    }

    public void getShortestPath(T city1,T city2)
    {
        int index1 = getIndex(city1);
        int index2 = getIndex(city2);

        if (shortestPathLength(index1,index2)==0)
            System.out.println(city1+"和"+city2+"之间无法连通");
        else {
            String result = "";
            Iterator iterator = iteratorShortestPath(index1,index2);
            while (iterator.hasNext()) {
                result += iterator.next() + " ";
            }
            System.out.println("从"+city1+"到"+city2+"的最短路径为："+result);

            System.out.println("最短路径长度为："+shortestPathLength(index1,index2));
        }
    }

    public void getShortestWeightPath(T city1,T city2)
    {

        if (shortestPathLength(city1,city2) < Double.POSITIVE_INFINITY)
            System.out.println("从"+city1+"到"+city2+"最便宜的价钱为："+shortestPathWeight(city1,city2));
        else
            System.out.println(city1+"和"+city2+"之间无法连通");
    }
}

